package com.bbzn.device.client.service.emq.order.impl.mq;

import com.alibaba.fastjson.JSONObject;
import com.bbzn.device.client.config.EmqCode;
import com.bbzn.device.client.constant.DeviceConstant;
import com.bbzn.device.client.constant.GroupConstant;
import com.bbzn.device.client.dataobject.SystemParam;
import com.bbzn.device.client.exception.DefinitException;
import com.bbzn.device.client.service.GroupDeviceService;
import com.bbzn.device.client.service.SystemParamByCacheService;
import com.bbzn.device.client.utils.Base64Util;
import com.bbzn.device.client.utils.OptionalBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @Author wulongbo
 * @Date 2021/12/16 16:19
 * @Version 1.0
 */
@Component
public class MqMassMessagingImpl extends BaseMqSendImpl {

    @Autowired
    private SystemParamByCacheService systemParamByCacheService;

//    @Autowired
//    private GroupDeviceService groupDeviceService;

//    @Override
//    protected void setTopic(String topic) {
//        String groupTopic = groupDeviceService.getTopic((Long) map.get("groupId"));
//        this.topic = EmqCode.sendTopic + groupTopic + EmqCode.endTopic;
//    }

    @Override
    public String checkMap(String language) throws Exception {
//        if (!OptionalBean.ofNullable(map.get("groupId")).isPresent()) {
//            SystemParam systemParam = systemParamByCacheService.getValues(GroupConstant.GROUP_ENUM, GroupConstant.GROUP_NO_ID_PREFIX + language);
//            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
//        }
        if (!OptionalBean.ofNullable(map.get("content")).isPresent()) {
            SystemParam systemParam = systemParamByCacheService.getValues(DeviceConstant.DEVICE_ENUM, DeviceConstant.DEVICE_NO_CONTENT_PREFIX + language);
            throw new DefinitException(systemParam.getCode(), systemParam.getMassage());
        }
        return JSONObject.toJSONString(map);
    }
}
